<?php

/**
 * comments actions.
 *
 * @package    blog
 * @subpackage comments
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class sfBlogCommentsActions extends sfActions
{
	
	/*public function executeComm(sfWebRequest $request)
	{
		 if($this->getUser()->isAuthenticated()) {
		 $this->form2 = new BlogCommentForm();
        

		if ($request->isMethod('post'))
		{
			$this->form2->bind($request->getParameter($this->form2->getName()));

			if ($this->form2->isValid())
			{
				 $article = $this->form2->save();
				 $article =  Doctrine_Core::getTable('BlogArticle')->getArticleByComm($this->form2->getValue('article_id'));
				foreach ($article as $blogarticle) {
				 $this->redirect('show_articles', $blogarticle); 
			 }
			}
		}
	 }
	}*/
	
	
	
  public function executeIndex(sfWebRequest $request)
  {
    $this->blog_comments = Doctrine_Core::getTable('ShopProduct')
      ->createQuery('a')
      ->execute();
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->blog_comment = Doctrine_Core::getTable('ShopProduct')->find(array($request->getParameter('id')));
    $this->forward404Unless($this->blog_comment);
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new BlogCommentForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new BlogCommentForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($blog_comment = Doctrine_Core::getTable('ShopProduct')->find(array($request->getParameter('id'))), sprintf('Object blog_comment does not exist (%s).', $request->getParameter('id')));
    $this->form = new BlogCommentForm($blog_comment);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($blog_comment = Doctrine_Core::getTable('ShopProduct')->find(array($request->getParameter('id'))), sprintf('Object blog_comment does not exist (%s).', $request->getParameter('id')));
    $this->form = new BlogCommentForm($blog_comment);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($blog_comment = Doctrine_Core::getTable('ShopProduct')->find(array($request->getParameter('id'))), sprintf('Object blog_comment does not exist (%s).', $request->getParameter('id')));
    $blog_comment->delete();

    $this->redirect('products/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $blog_comment = $form->save();

      $this->redirect('products/edit?id='.$blog_comment->getId());
    }
  }
}





